package com.coollang.smartbra.activity;

import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.coollang.smartbra.MyAutoLayoutActivity;
import com.coollang.smartbra.R;
import com.coollang.smartbra.adapter.ViconDataAdapter;
import com.coollang.smartbra.constant.ResourceList;
import com.coollang.smartbra.model.ViconDataRecycleData;
import com.coollang.smartbra.utils.ActivitySwitcher;
import com.coollang.smartbra.utils.TranslucentSystemBarUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Timmy
 *         动作库页面
 */
public class ViconDataActivity extends MyAutoLayoutActivity {
    @BindView(R.id.status_bar)
    View statusBar;
    @BindView(R.id.tv_title)
    TextView mTvTitle;
    @BindView(R.id.iv_right)
    ImageView ivRight;
    @BindView(R.id.content)
    LinearLayout content;
    @BindView(R.id.iv_back)
    ImageView mIvBack;
    @BindView(R.id.vicon_reycle)
    RecyclerView mRecyclerView;

    public ViconDataAdapter mViconDataAdapter;

    @Override
    protected void initView() {
        setContentView(R.layout.activity_vicondata);
        ButterKnife.bind(this);
        TranslucentSystemBarUtils.showChenJinZhuangTaiLan(statusBar, this, content);
        initViews();
    }

    private void initViews() {
        mIvBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ivRight.setVisibility(View.GONE);
        mTvTitle.setText(getString(R.string.motion_database));
        mTvTitle.setTextColor(ContextCompat.getColor(this, R.color.black_80));

        mViconDataAdapter = new ViconDataAdapter(null);
        mRecyclerView.setAdapter(mViconDataAdapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));

        mViconDataAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                // 跳转页面
                ActivitySwitcher.gotoActionDetail(ViconDataActivity.this, position);
            }
        });
    }

    @Override
    protected void initData() {
        // 初始化视频数据
        initRecycleViewData();
    }

    public void initRecycleViewData() {
        final List<ViconDataRecycleData> recycleDatas = new ArrayList<>();

        String[] actionListTexts = ResourceList.ACTION_NAME_LIST;
        int[] actionListIvs = ResourceList.ACTION_LIST_IVS;

        int length = actionListTexts.length - 1;
        for (int i = 0; i < length; i++) {
            ViconDataRecycleData recycleData = new ViconDataRecycleData();
            recycleData.setTvTitle(actionListTexts[i]);
            recycleData.setBitmap(actionListIvs[i]);
            recycleDatas.add(recycleData);
        }
        mViconDataAdapter.addData(recycleDatas);
    }
}
